/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import java.util.List;
import javax.swing.JOptionPane;
import utils.Decaimento;

/**
 *
 * @author roberto
 */
public class Inicio extends javax.swing.JFrame {

    /**
     * Creates new form Inicio
     */
    public Inicio() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelConteudo = new javax.swing.JPanel();
        painelCampos = new javax.swing.JPanel();
        rotuloNumeroFaces = new javax.swing.JLabel();
        campoTextoNumeroFaces = new javax.swing.JTextField();
        rotuloNumeroDados = new javax.swing.JLabel();
        botaoCalcular = new javax.swing.JButton();
        campoTextoNumeroDados = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        areaTextoDecaimento = new javax.swing.JTextArea();
        rotuloImagem = new javax.swing.JLabel();
        rotuloLancamentos = new javax.swing.JLabel();
        rotuloDados = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dado 0.3");
        setBackground(new java.awt.Color(255, 255, 255));
        setResizable(false);

        painelConteudo.setBackground(new java.awt.Color(255, 255, 255));

        painelCampos.setBackground(new java.awt.Color(254, 254, 254));
        painelCampos.setBorder(null);

        rotuloNumeroFaces.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        rotuloNumeroFaces.setForeground(new java.awt.Color(0, 27, 255));
        rotuloNumeroFaces.setText("Numero de Faces:");

        rotuloNumeroDados.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        rotuloNumeroDados.setForeground(new java.awt.Color(0, 27, 255));
        rotuloNumeroDados.setText("Numero de Dados:");

        botaoCalcular.setText("Calcular");
        botaoCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCalcularActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelCamposLayout = new javax.swing.GroupLayout(painelCampos);
        painelCampos.setLayout(painelCamposLayout);
        painelCamposLayout.setHorizontalGroup(
            painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCamposLayout.createSequentialGroup()
                .addGroup(painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rotuloNumeroDados)
                    .addComponent(rotuloNumeroFaces))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoTextoNumeroDados, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoTextoNumeroFaces, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addComponent(botaoCalcular, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                .addContainerGap())
        );
        painelCamposLayout.setVerticalGroup(
            painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCamposLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(painelCamposLayout.createSequentialGroup()
                        .addComponent(botaoCalcular, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(1, 1, 1))
                    .addGroup(painelCamposLayout.createSequentialGroup()
                        .addGroup(painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(campoTextoNumeroDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rotuloNumeroDados))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(painelCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(campoTextoNumeroFaces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rotuloNumeroFaces))))
                .addGap(65, 65, 65))
        );

        areaTextoDecaimento.setColumns(20);
        areaTextoDecaimento.setFont(new java.awt.Font("Ubuntu Light", 1, 14)); // NOI18N
        areaTextoDecaimento.setForeground(new java.awt.Color(32, 31, 237));
        areaTextoDecaimento.setRows(5);
        jScrollPane1.setViewportView(areaTextoDecaimento);

        rotuloImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ui/10-dados-coloridos-para-jogos.jpg"))); // NOI18N

        rotuloLancamentos.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        rotuloLancamentos.setText("Lancamentos");

        rotuloDados.setFont(new java.awt.Font("Ubuntu", 1, 13)); // NOI18N
        rotuloDados.setText("Dados Restantes");

        javax.swing.GroupLayout painelConteudoLayout = new javax.swing.GroupLayout(painelConteudo);
        painelConteudo.setLayout(painelConteudoLayout);
        painelConteudoLayout.setHorizontalGroup(
            painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rotuloImagem)
                .addGap(18, 18, 18)
                .addGroup(painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelCampos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(painelConteudoLayout.createSequentialGroup()
                            .addComponent(rotuloLancamentos)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(rotuloDados))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painelConteudoLayout.setVerticalGroup(
            painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelConteudoLayout.createSequentialGroup()
                .addGroup(painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelConteudoLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(painelCampos, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addGroup(painelConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rotuloLancamentos)
                            .addComponent(rotuloDados))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(painelConteudoLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rotuloImagem)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelConteudo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCalcularActionPerformed
        // TODO add your handling code here:
        if ((!campoTextoNumeroDados.getText().equals("")) && (!campoTextoNumeroFaces.getText().equals(""))) {
            try{
            int nDados = Integer.parseInt(campoTextoNumeroDados.getText());
            int nFaces = Integer.parseInt(campoTextoNumeroFaces.getText());
            Decaimento dec = new Decaimento(nDados, nFaces);
            List<String> resultados = dec.getResultados();
            StringBuilder texto = new StringBuilder();
            for(String s: resultados){
                texto.append(s);
            }
            areaTextoDecaimento.setText(texto.toString());
            } catch(NumberFormatException e){
                JOptionPane.showMessageDialog(this, "Erro na conversão de dados. Por favor, verifique se o dado inserido é realmente válido.",
                        "Erro",JOptionPane.ERROR_MESSAGE);
            } catch(Exception e){
                JOptionPane.showMessageDialog(this, "Erro. Consulte o desenvolvedor.",
                        "Erro",JOptionPane.ERROR_MESSAGE);               
            }
        } else {
            JOptionPane.showMessageDialog(this, "Por favor, preencha todos os campos.", "Aviso", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_botaoCalcularActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("GTK+".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Inicio().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areaTextoDecaimento;
    private javax.swing.JButton botaoCalcular;
    private javax.swing.JTextField campoTextoNumeroDados;
    private javax.swing.JTextField campoTextoNumeroFaces;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel painelCampos;
    private javax.swing.JPanel painelConteudo;
    private javax.swing.JLabel rotuloDados;
    private javax.swing.JLabel rotuloImagem;
    private javax.swing.JLabel rotuloLancamentos;
    private javax.swing.JLabel rotuloNumeroDados;
    private javax.swing.JLabel rotuloNumeroFaces;
    // End of variables declaration//GEN-END:variables
}
